import java.util.concurrent.Semaphore;

/**
 * @author Yinzi Chen
 * @date Nov 13, 2013
 */
public class H2O {

    private Semaphore p1;
    private Semaphore p2;

    public H2O() {
        p1 = new Semaphore(0);
        p2 = new Semaphore(0);
    }

    public void H() {
        p1.release(1);
        try {
            p2.acquire(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void O() {
        p2.release(2);
        try {
            p1.acquire(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

    }

}
